package AcWing周赛;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-08-20
 * Time: 19:41
 */
public class Demo65_2 {
    private static int N = 1 << 18;

    public static void main(String[] args) {
        int[] cnt = new int[N];
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        while(t-- > 0){
            String op = scanner.next();
            String str = scanner.next();
            int x = 0;
            int len = str.length();
            for(int i = 0; i < len; i++){
                x = x * 2 + str.charAt(i) % 2;
            }
            if (op.compareTo("+") == 0){
                cnt[x]++;
            }else if (op.compareTo("-") == 0){
                cnt[x]--;
            }else {
                System.out.println(cnt[x]);
            }
        }
    }
}
